//
//  DZHomeViewController.m
//  Weico
//
//  Created by 大泽 on 15/7/21.
//  Copyright (c) 2015年 刘洪泽. All rights reserved.
//

#import "DZHomeViewController.h"
#import "DZTest1ViewController.h"
#import "DZTest2ViewController.h"
#import "DZDropMenu.h"
#import "DZDropDownViewController.h"
@interface DZHomeViewController () <DZDropMenuDelegate>

@property (nonatomic, weak) UIButton *titleView;


@end

@implementation DZHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarger:self action:@selector(friendSearch) title:nil image:@"navigationbar_friendsearch" highImage:@"navigationbar_friendsearch_highlighted"];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarger:self action:@selector(pop) title:nil image:@"navigationbar_pop" highImage:@"navigationbar_pop_highlighted"];
    
    UIButton *titleView = [[UIButton alloc] init];
    titleView.width = 200;
    titleView.height = 30;
    [titleView setTitle:@"首页" forState:UIControlStateNormal];
    [titleView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [titleView setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];
    [titleView setImage:[UIImage imageNamed:@"navigationbar_arrow_up"] forState:UIControlStateSelected];
    [titleView addTarget:self action:@selector(titleViewClick:) forControlEvents:UIControlEventTouchUpInside];
    
    titleView.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 40);
    titleView.imageEdgeInsets = UIEdgeInsetsMake(0, 90, 0, 0);
    
    self.navigationItem.titleView = titleView;
    _titleView = titleView;
}

- (void)titleViewClick:(UIButton *)button
{
    DZDropMenu *menu = [DZDropMenu showFrom:button];
    menu.delegate = self;
    DZDropDownViewController *dropDownVc = [[DZDropDownViewController alloc] init];
        dropDownVc.view.height = 100;
     menu.contentVc = dropDownVc;
   
}


#pragma mark - DZDropMenuDelegate
- (void)dropMenuDidShow:(DZDropMenu *)dropMenu{
    
    _titleView.selected = YES;
    
}

- (void)dropMenuDidDissmiss:(DZDropMenu *)dropMenu{
    
    _titleView.selected = NO;
}

- (void)friendSearch{
    
    DZLog(@"friendSearch");
}

- (void)pop{
    
    DZLog(@"pop");
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    DZTest1ViewController *vc = [[DZTest1ViewController alloc]init];
    vc.view.backgroundColor = DZRandomColor;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
